using System;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace UnitTesting.Fixturing
{
	static class DynamicProxyReflector
	{
		const string AssemblyName = "DynamicProxyGenAssembly2";

		internal static bool IsInternalVisibleType(Type type)
		{
			return type.Assembly.GetCustomAttributes(false).Any(IsInternalVisibleImp);
		}

		static bool IsInternalVisibleImp(object attribute)
		{
			var internalsVisibleToAttribute = attribute as InternalsVisibleToAttribute;
			return internalsVisibleToAttribute != null
			       && new AssemblyName(internalsVisibleToAttribute.AssemblyName).Name == AssemblyName;
		}
	}
}